package zuoye;

public class StackList {
    StackNode head = new StackNode();

    public void  push(Student date){
        StackNode node = new StackNode();
        node.date = date;

        node.next = head.next;
        head.next = node;

    }

    public void pop(){
       head.next = head.next.next;
    }

    public Student  top() {
    if(head.next!=null){
        System.out.println("此表为空");
        return null;
    }
    return head.next.date;
    }

    public void clear(){
        head.next=null;
    }

    public boolean isEmpty(){
        return head.next==null;
    }

    public int length(){
        int x =0;
        for(StackNode node = head.next;node!=null;node=node.next){
            x++;
        }
        return x;
    }

    public void display(){
        if(head.next==null){
            System.out.println("此表为空");
            return;
        }
        for(StackNode node = head.next;node!=null;node=node.next){
            System.out.print(node.date  +"  ");
        }
        System.out.println();
    }
}
